package com.demo.zlb.sso.login;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @author shiyuchen
 * @date 2023-04-12
 */
@SpringBootTest
@Slf4j
public class client {
    @Value("${zzdingTalk.domainName}")
    private static String domainName;
    @Value("${zzdingTalk.appKey}")
    private static String appKey;
    @Value("${zzdingTalk.appSecret}")
    private static String appSecret;
    @Value("${zzdingTalk.protocal}")
    private static String protocal;
    @Value("${zzdingTalk.tenantId}")
    private static String tenantId;

    @Test
    void getBookPermissions() {
        ExecutableClient executableClient = ExecutableClient.getInstance();
        executableClient.setDomainName(domainName);
        executableClient.setProtocal(protocal);
        executableClient.setAccessKey(appKey);
        executableClient.setSecretKey(appSecret);
        executableClient.init();
        String api = "/auth/scopesV2";
        PostClient postClient = executableClient.newPostClient(api);
        postClient.addParameter("tenantId", tenantId);
        String apiResult = postClient.post();
        log.info("获取浙政钉获取通讯录权限：{}", apiResult);
        JSONObject jsonObject = JSONObject.parseObject(apiResult);
        if (jsonObject.getBoolean("success")) {
            log.info("result:{}", jsonObject.getJSONObject("content"));
            //return jsonObject.getJSONObject("content");
        }
        //return null;
    }
}
